package com.ruoyi.web.controller.dm;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dm.domain.DataManagementParam;
import com.ruoyi.dm.domain.TableInfoParam;
import com.ruoyi.dm.service.DataManangementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dm/dataManage")
@Api(value = "DataManagementController", tags = "资料管理")
public class DataManagementController extends BaseController {

    @Resource
    private DataManangementService dataManangementService;

    //@PreAuthorize("@ss.hasPermi('dm:dataManage:add')")
    @ApiOperation(value = "新增资料", notes = "新增资料")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DataManagementParam param) {
        return dataManangementService.add(param);
    }

    //@PreAuthorize("@ss.hasPermi('dm:dataManage:list')")
    @ApiOperation(value = "获取资料列表", notes = "获取资料列表")
    @GetMapping("/list")
    public TableDataInfo list(DataManagementParam param) {
        startPage();
        List<DataManagementParam> list = dataManangementService.selectList(param);
        return getDataTable(list);
    }
    /**
     * 表结构信息获取
     */
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:getInfo')")
    @ApiOperation(value = "跟据资料ID获取表结构",response = TableInfoParam.class)
    @GetMapping("/getInfo/{dataId}")
    @Log(title = "表结构管理-跟据资料ID获取表结构", businessType = BusinessType.INSERT)
    public AjaxResult getInfo(@ApiParam(value = "资料ID", name = "dataId", required = true)@PathVariable(value = "dataId") Long dataId) {
        return dataManangementService.getInfo(dataId);
    }
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:saveTable')")
    @ApiOperation("表结构保存")
    @Log(title = "表结构管理-表结构保存", businessType = BusinessType.UPDATE)
    @PostMapping("/saveTable")
    public AjaxResult saveTable(@RequestBody DataManagementParam param) {
        return dataManangementService.saveTable(param);
    }
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:isTable')")
    @ApiOperation("查看表是否")
    @GetMapping("/isTable/{dataId}")
    public AjaxResult isTable(@ApiParam(value = "资料ID", name = "dataId", required = true)@PathVariable(value = "dataId") Long dataId) {
        return dataManangementService.isTable(dataId);
    }
    /**
     * 表结构创建
     */
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:createTable')")
    @ApiOperation("sql建表")
    @PostMapping("/createTable/{dataId}")
    @Log(title = "表结构管理-表结构创建", businessType = BusinessType.INSERT)
    public AjaxResult createTable(@ApiParam(value = "资料ID", name = "dataId", required = true)@PathVariable("dataId") Long dataId) {
        return dataManangementService.createTable(dataId);
    }

    /**
     * 修改资料
     */
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:edit')")
    @Log(title = "修改资料", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改资料")
    public AjaxResult edit(@RequestBody DataManagementParam param)
    {
        return dataManangementService.edit(param);
    }

    /**
     * 删除资料
     */
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:remove')")
    @Log(title = "字典类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除资料")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return dataManangementService.delete(ids);
    }

    /**
     * 刷新页面进行所有sse通道关闭
     */
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:offChannel')")
    @PostMapping("/offChannel")
    @ApiOperation("刷新页面进行所有sse通道关闭")
    public void offChannel() {
        dataManangementService.offChannel();
    }
    /**
     * 表结构创建
     */
    //@PreAuthorize("@ss.hasPermi('dm:dataManage:insertFuture')")
    @ApiOperation("进行数据未来新增")
    @PostMapping("/{indexs}")
    public AjaxResult insertFuture(@PathVariable List<String> indexs) {
        return dataManangementService.insertFuture(indexs);
    }

}
